package Ui.guiComponents;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;


/**
 *
 * @author Elya
 */

public class Players extends JPanel {
    
    private javax.swing.JList PlayersList;
    private javax.swing.JButton addPlayer;
    private javax.swing.JButton buttonMoveUp;
    private javax.swing.JButton buttonMoveDown;
    private javax.swing.JScrollPane playerScrollPane;
    private javax.swing.JButton buttonRemovePlayer;
    private javax.swing.JLabel labelChangeOrder;
    
    private  UiData PlayersData;
    private MainWindow mainWin;
    
    public Players(UiData PlayersData,MainWindow mainWin ){
       
        this.mainWin=mainWin;
        init();
        this.PlayersData=PlayersData;
    }
  
    private void init(){
        playerScrollPane = new javax.swing.JScrollPane();
        PlayersList = new javax.swing.JList();
        addPlayer = new javax.swing.JButton();
        buttonRemovePlayer = new javax.swing.JButton();
        buttonMoveUp = new javax.swing.JButton();
        buttonMoveDown = new javax.swing.JButton();
        labelChangeOrder = new javax.swing.JLabel();
        
        setBackground(new java.awt.Color(83, 138, 219));
        setLayout(new BorderLayout());

        setBackground(new java.awt.Color(83, 138, 219));
        setBorder(javax.swing.BorderFactory.createEtchedBorder());
        setMinimumSize(new java.awt.Dimension(140, 300));
        setMaximumSize(new java.awt.Dimension(140, 300));


        PlayersList.setBackground(new java.awt.Color(153,204,255));
        PlayersList.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Players", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 18), new java.awt.Color(51, 51, 51))); // NOI18N
        PlayersList.setFont(new java.awt.Font("Arial", 0, 11)); 
        PlayersList.setForeground(new java.awt.Color(255, 255, 255));
        PlayersList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = {  };
            @Override
            public int getSize() { return strings.length; }
            @Override
            public Object getElementAt(int i) { return strings[i]; }
        });
        PlayersList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        PlayersList.setToolTipText("Choose Player");
        PlayersList.setSelectionBackground(new java.awt.Color(83, 138, 219));
        PlayersList.setVisibleRowCount(6);
        PlayersList.setMaximumSize(new Dimension(70, 70));
        playerScrollPane.setViewportView(PlayersList);
        playerScrollPane.setPreferredSize(new Dimension(135,80));
        playerScrollPane.setAlignmentX(LEFT_ALIGNMENT);


        
        addPlayer.setBackground(new java.awt.Color(83, 138, 219));
        addPlayer.setText("add player");

        buttonRemovePlayer.setBackground(new java.awt.Color(83, 138, 219));
        buttonRemovePlayer.setText("remove player");

        
        JPanel addRemoveButtonsPane = new JPanel();
        addRemoveButtonsPane.setBackground(new java.awt.Color(83, 138, 219));
        addRemoveButtonsPane.setLayout(new BoxLayout(addRemoveButtonsPane, BoxLayout.Y_AXIS));
        //addRemoveButtonsPane.add(Box.createVerticalGlue());

        addRemoveButtonsPane.add(Box.createRigidArea(new Dimension(0, 10)));
        addRemoveButtonsPane.add(addPlayer);
        addRemoveButtonsPane.add(Box.createRigidArea(new Dimension(0, 10)));
        addRemoveButtonsPane.add(buttonRemovePlayer);
        addRemoveButtonsPane.add(Box.createRigidArea(new Dimension(0, 40)));

        addPlayer.setAlignmentX(JButton.CENTER_ALIGNMENT);
        buttonRemovePlayer.setAlignmentX(JButton.CENTER_ALIGNMENT);
        

        labelChangeOrder.setFont(new java.awt.Font("Arial", 1, 11));
        labelChangeOrder.setText("Turn Order");

        labelChangeOrder.setToolTipText("player name");

        labelChangeOrder.setAlignmentX(Component.CENTER_ALIGNMENT);
        labelChangeOrder.setAlignmentY(Component.CENTER_ALIGNMENT);

        
        
        buttonMoveUp.setBackground(new java.awt.Color(83, 138, 219));
        buttonMoveUp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Ui/guiComponents/images/upicon.jpg"))); // NOI18N
        buttonMoveUp.setToolTipText("move player up");
        buttonMoveUp.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonMoveUp.setMaximumSize(new Dimension(26,26));

        buttonMoveDown.setBackground(new java.awt.Color(83, 138, 219));
        buttonMoveDown.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Ui/guiComponents/images/downicon.jpg"))); // NOI18N
        buttonMoveDown.setToolTipText("move player up");
        buttonMoveDown.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonMoveDown.setMaximumSize(new Dimension(26,26));
        
        JPanel moveButtonsPane = new JPanel();
        moveButtonsPane.setBackground(new java.awt.Color(83, 138, 219));
        moveButtonsPane.setMaximumSize(new Dimension(70, 70));
        moveButtonsPane.setLayout(new BoxLayout(moveButtonsPane, BoxLayout.Y_AXIS));
        moveButtonsPane.add(Box.createVerticalGlue());
        moveButtonsPane.add(labelChangeOrder);
        moveButtonsPane.add(Box.createRigidArea(new Dimension(0, 5)));
        moveButtonsPane.add(buttonMoveUp);
        moveButtonsPane.add(Box.createRigidArea(new Dimension(0, 10)));
        moveButtonsPane.add(buttonMoveDown);
        buttonMoveUp.setAlignmentX(JButton.CENTER_ALIGNMENT);
        buttonMoveDown.setAlignmentX(JButton.CENTER_ALIGNMENT);

        Dimension dimSize = new Dimension(220,300);
        
        add(addRemoveButtonsPane,BorderLayout.PAGE_START);
        add(playerScrollPane,BorderLayout.LINE_START);
        add(moveButtonsPane,BorderLayout.CENTER);
        add(new Box.Filler(dimSize, dimSize, dimSize),BorderLayout.PAGE_END);
    
        MainListener mListener = mainWin.getMwListener();
        addPlayer.addActionListener(mListener.new AddPlayersAdapter());
        buttonMoveUp.addMouseListener(mListener.new buttonMoveUpAdapter());
        buttonMoveDown.addMouseListener(mListener.new buttonMoveDwonAdapter());
        playerScrollPane.addMouseListener(mListener.new playerScrollPaneAdapter());
        buttonRemovePlayer.addMouseListener(mListener.new buttonRemovePlayerAdapter());
    }
    
    
    
}

